// src/utils/eventBus.js
import { ref } from 'vue';

const eventBus = {
  events: ref({}),

  $on(eventName, callback) {
    if (!this.events.value[eventName]) {
      this.events.value[eventName] = [];
    }
    this.events.value[eventName].push(callback);
  },

  $off(eventName, callback) {
    if (this.events.value[eventName]) {
      this.events.value[eventName] = this.events.value[eventName].filter(cb => cb !== callback);
    }
  },

  $emit(eventName, ...args) {
    if (this.events.value[eventName]) {
      this.events.value[eventName].forEach(callback => callback(...args));
    }
  }
};

export default eventBus;